package com._101aiot.consumer.controller;

import com._101aiot.api.DubboApiService;
import com._101aiot.common.resultutil.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/consumer")
public class DubboTestConsumerController {


    /**
     * version
     * retries 重试次数，默认2次 不算首次调用的
     */
    @DubboReference(version = "1.0.0", check = false,retries = 0)
    private DubboApiService dubboApiService;

    @GetMapping("/getUserName")
    public CommonResult<String> getUserName() {
        try{
            return CommonResult.success(dubboApiService.getUserName());
        } catch (Exception e){
            log.info("cause:{};-----> 报错信息：{}", e.getCause(), e.getMessage());
            return CommonResult.failed("调用失败，请重试！");
        }

    }

}
